USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Insert]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Insert record into table [dbo].[Users_Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Insert]
	/*@RowNumber int =Null  , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Users_Groups](/*[RowNumber], [ID], [User_ID], [Group_ID]*/)
	VALUES     (/*@RowNumber, @ID, @User_ID, @Group_ID*/)

	/**/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-update]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Update record in table [dbo].[Users_Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-update]
	/*@RowNumber int =Null  , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Users_Groups] SET 
		/*[RowNumber] =@RowNumber, 
		[ID] =@ID, 
		[User_ID] =@User_ID, 
		[Group_ID] =@Group_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/**/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Insert-Update]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Insert OR Update record into table [dbo].[Users_Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Insert-Update]
	/*@RowNumber int =Null  , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Users_Groups] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Users_Groups](/*[RowNumber], [ID], [User_ID], [Group_ID]*/)
		VALUES     (/*@RowNumber, @ID, @User_ID, @Group_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Users_Groups] SET 
			/*[RowNumber] =@RowNumber, 
			[ID] =@ID, 
			[User_ID] =@User_ID, 
			[Group_ID] =@Group_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/**/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Delete]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	delete records from table [dbo].[Users_Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Users_Groups]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Select]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	select records from table [dbo].[Users_Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Users_Groups]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )*/
END
GO
-- =============================================
